package com.jcy.common.configuration;

import com.jcy.common.annotation.EnableJcyCommon;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.Map;

/**
 * @Description:
 * @Auther: jcy
 * @Date: 2021/6/25 15:39
 */
public class CommonConfiger implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        ArrayList<String> beanNames = new ArrayList<>();

        Map<String, Object> common = annotationMetadata.getAnnotationAttributes(EnableJcyCommon.class.getName());

        assert common != null;

        boolean ehcache = (boolean) common.getOrDefault("ehcache", false);

        if (ehcache) {
            beanNames.add(EhcacheConfig.class.getName());
        }

        return beanNames.toArray(new String[0]);
    }
}
